/**
 * Created by zhangqingxi on 2017-04-20.
 */


var disposeModelPath=ROOT_PATH+'/environmental/solidWaste/dispose/';




var disposeData;
var outsourcingUnitData;
var exportingCountryData;
$(function () {


    loadDisposeMethodData();

    loadOutsourcingUnit();

    loadExportingCountry();

    deptLoadSuccess();
    solidWasteTypeLoadSuccess();

    initShape();
    initGenerationSource();

    loadUnitDisposeList();
    loadEntrustDisposeList();
    loadExitDisposeList();


});
/**
 * 加载处理处理方法
 */
function loadDisposeMethodData(){
    $.ajax({
        url: dictionaryByCode+dictionaryDisposeMethod,
        type:'POST',
        dataType:'json',
        async:false,
        success: function (data) {
            disposeData=data;
        }
    });
}
/**
 * 加载外委单位数据
 */
function loadOutsourcingUnit() {
    $.ajax({
        url: findOu,
        type:'POST',
        dataType:'json',
        async:false,
        success: function (data) {
            outsourcingUnitData=data;
        }
    });
}
/**
 * 加载出口国
 */
function loadExportingCountry() {
    $.ajax({
        url: dictionaryByCode+dictionaryExportingCountry,
        type:'POST',
        dataType:'json',
        async:false,
        success: function (data) {
            exportingCountryData=data;
        }
    });
}

/**
 * 处理方法格式化
 * @param value
 * @param rowData
 * @param rowIndex
 */
function disposeMethodFormatter(value, rowData, rowIndex) {

    for (var i = 0; i < disposeData.length; i++) {
        if (disposeData[i].id == value) {
            return disposeData[i].text;
        }
    }
}
/**
 * 格式化外委单位
 * @param value
 * @param rowData
 * @param rowInde
 */
function outsourcingUnitFormatter(value, rowData, rowInde) {
    for (var i = 0; i < outsourcingUnitData.length; i++) {
        if (outsourcingUnitData[i].id == value) {
            return outsourcingUnitData[i].text;
        }
    }
}
/**
 * 格式化出口国
 * @param value
 * @param rowData
 * @param rowIndex
 */
function exportingCountryFormatter(value, rowData, rowIndex) {

    for (var i = 0; i < exportingCountryData.length; i++) {
        if (exportingCountryData[i].id == value) {
            return exportingCountryData[i].text;
        }
    }
}

/**
 * 加载内部处理表格
 */
function  loadUnitDisposeList() {
    var swaId=$('#swaId').val();
    var url=findUnitDisposeBySwaId+swaId;

    $('#unitDisposeList').datagrid({
        url:url,
        method:'get',
        title:'处理方式-单位内部设施处置利用',
        fitColumns:true,
       // rownumbers:true,
        singleSelect:true,
        striped:true,
        fit:true,
        columns:[[

            {field:'startDate',title:'处理开始日期',width:10,
                editor:{
                    type:'datebox',
                    options: {
                        editable: false,
                        required: true
                    }
                }
            },
            {field:'endDate',title:'处理结束日期',width:10,
                editor:{
                    type:'datebox',
                    options: {
                        editable: false,
                        required: true
                    }
                }
            },
            {field:'method',title:'处理方法',width:10,
                editor:{
                    type:'combobox',
                    options: {
                        required: true,
                        editable: false,
                        valueField:'id',
                        textField:'text',
                        data:disposeData
                    }
                },
                formatter:disposeMethodFormatter
            },
            {field:'number',title:'处理数量',width:10,
                editor:{
                    type:'numberspinner',
                    options: {
                        required: true,
                        precision:2,
                        min:0
                    }
                }
            }
        ]],
        toolbar: '#unitDisposeToolbar'
    });
}
/**
 * 加载外委单位处理表格
 */
function  loadEntrustDisposeList() {
    var swaId=$('#swaId').val();
    var url=findEntrustDisposeBySwaId+swaId;
    $('#entrustDisposeList').datagrid({
        url:url,
        title:'处理方式-提供或委托处理利用',
        fitColumns:true,
       // rownumbers:true,
        singleSelect:true,
        striped:true,
        fit:true,
        columns:[[

            {field:'startDate',title:'处理开始日期',width:10,
                editor:{
                    type:'datebox',
                    options: {
                        editable: false,
                        required: true
                    }
                }
            },
            {field:'endDate',title:'处理结束日期',width:10,
                editor:{
                    type:'datebox',
                    options: {
                        editable: false,
                        required: true
                    }
                }
            },
            {field:'outsourcingUnitId',title:'外委单位',width:10,
                editor:{
                    type:'combobox',
                    options: {
                        required: true,
                        editable: false,
                        valueField:'id',
                        textField:'text',
                        data:outsourcingUnitData
                    }
                },
               formatter:outsourcingUnitFormatter
            },
            {field:'number',title:'处理数量',width:10,
                editor:{
                    type:'numberspinner',
                    options: {
                        required: true,
                        precision:2,
                        min:0
                    }
                }
            }
        ]],
        toolbar: '#entrustDisposeToolbar'
    });
}
/**
 * 加载出口处理表格
 */
function  loadExitDisposeList() {
    var swaId=$('#swaId').val();
    var url=findExitDisposeBySwaId+swaId;
    $('#exitDisposeList').datagrid({
        url:url,
        title:'处理方式-出口',
        fitColumns:true,
       // rownumbers:true,
        singleSelect:true,
        striped:true,
        fit:true,
        columns:[[

            {field:'startDate',title:'处理日期',width:10,
                editor:{
                    type:'datebox',
                    options: {
                        editable: false,
                        required: true
                    }
                }
            },
            {field:'exportingCountry',title:'出口国',width:10,
                editor:{
                    type:'combobox',
                    options: {
                        required: true,
                        editable: false,
                        valueField:'id',
                        textField:'text',
                        data:exportingCountryData
                    }
                },
                formatter:exportingCountryFormatter
            },
            {field:'number',title:'出口数量',width:10,
                editor:{
                    type:'numberspinner',
                    options: {
                        required: true,
                        precision:2,
                        min:0
                    }
                }
            }
        ]],
        toolbar: '#exitDisposeToolbar'
    });
}